package com.ztom.top100;

/**
 * 盛最多的水
 * <p>
 * https://leetcode-cn.com/problems/container-with-most-water/
 *
 * @author ZhangTao
 */
public class Code07MaxArea {

    public int maxArea(int[] height) {
        int l = 0;
        int r = height.length - 1;
        int max = 0;
        int area = 0;
        while (l < r) {
            if (height[l] <= height[r]) {
                area = height[l] * (r - l);
                l++;
            } else {
                area = height[r] * (r - l);
                r--;
            }
            max = Math.max(max, area);
        }
        return max;
    }
}
